home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu300.dms / pu300.adf / Tutor.1 / morse.s < prev    next >
Text File  |  1990-05-26  |  61KB  |  1,575 lines

  1. ** morse.s Version 1.1
  2. ** A program in assembly language to make morse code sending and
  3. ** random code generating routines.  Started on April 30, 1097.
  4. ** By        Peter V. Inskeep    ars/ NO2D
  5. **           6 Clearview Drive
  6. **           Long Valley, N. J., 07853
  7. **           CIS  72017,1211
  8. **           CIS E-Mail inquiries encouraged
  9. ** Created primarily as an exploration of assembly language programming
  10. ** on the Amiga.  But it would be nice also if this adventure in morse
  11. ** code created enough enthusiasm to cause you to look into ham radio
  12. ** if you are not already a ham.  Contact a ham (look for big antennas
  13. ** in the back yard), or call ARRL in Newington, Ct., for the name of
  14. ** a ham club near you.
  15. *  = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -   *
  16. ***  Special thanks to Darrel Schneider, Author of SpriteClock, on ***
  17. ***  Fred Fish Disk # 43.  That program gave me the clues on how   ***
  18. ***  to open the timer.device and get it to _LVODoIO.  The source  ***
  19. ***  to Sclock has many very interesting assembly language ideas.  ***
  20. **  INCLUDE files normally used in compiling an assembly language
  21. ** program are not needed if the equates listed below are used.  There
  22. ** are obscure switches included to turn the equates on or off as
  23. ** you desire.  They are on now, so no INCLUDE directives are not needed.
  24. ** The equates are used to speed assembly, as running the assembler
  25. ** through many INCLUDE files takes a long time.
  26.  
  27. ;   INCLUDE    'exec/types.i' ;these will conflict with the equates
  28. ;   INCLUDE    'exec/io.i'    ;so are turned off by the [ ; ].
  29. ;   INCLUDE    'intuition/intuition.i' 
  30. ;   INCLUDE    'outfile.equ'  ;use this only if you have outfile.equ
  31. ; file built and installed in the include directory on assembly disk
  32. ** Some switches
  33. useoutfile  equ  1  ;equ 1 if you are not using outfile.equ
  34. useincludes equ  1  ;equ 1 if you are not using any includes at all
  35.    XREF   _LVOGetMsg
  36.    XREF   _LVOReplyMsg
  37.    XREF   _LVOAddPort
  38.    XREF   _LVORemPort
  39.    XREF   _LVOSetMenuStrip
  40.    XREF   _LVOClearMenuStrip
  41.    XREF   _LVOPrintIText
  42.    XREF   _LVODrawBorder
  43.    XREF   _LVOOpenWindow
  44.    XREF   _LVOCloseWindow
  45.    XREF   _LVOAddDevice
  46.    XREF   _LVOOpenDevice
  47.    XREF   _LVOCloseDevice
  48.    XREF   _LVORemDevice
  49.    XREF   _LVOOpenLibrary
  50.    XREF   _LVOCloseLibrary
  51.    XREF   _LVODoIO
  52.    XREF   _LVOSendIO
  53.    XREF   _LVOWait
  54.    XREF   _LVOAddGadget
  55.    XREF   _LVOAllocMem
  56.    XREF   _LVOFreeMem
  57.    XREF   _LVOAllocSignal
  58.    XREF   _LVOFreeSignal
  59.    XREF   _LVOFindTask
  60.  
  61. ** Outfile.equ equates - the following items are defined in a file called
  62. ** outfile.equ.  This file is created by assembling all of the desired
  63. ** INCLUDE files with the -e outfile.equ switch turned on.  The -e
  64. ** directive is not well documented in the literature, but is explained
  65. ** in one of the back issues of Transactor.  I can not remember which.
  66.  
  67.    IFEQ  1-useoutfile  ;IF NOT EQUAL ZERO THEN THESE ARE NOT USED
  68. AbsExecBase  EQU  $04
  69. NT_MSGPORT   EQU  $04
  70. NT_MESSAGE   EQU  $05
  71. LN_TYPE      EQU  $08
  72. LN_PRI       EQU  $09
  73. LN_NAME      EQU  $0A
  74. LN_SIZE      EQU  $0E
  75. MEMF_PUBLIC  EQU  $01
  76. MEMF_CHIP    EQU  $02
  77. MEMF_FAST    EQU  $04
  78. MEMF_CLEAR   EQU  $10000
  79.   ENDC
  80. ***   DMA CHIP ADDRESSES - FROM THE HARDWARE MANUAL
  81. ***   NOT CURRENTLY IN INCLUDE OR OUTFILE.EQU SO ALWAYS USE  
  82. Chipadr   equ $dff000      ;base address of chip
  83. DMAconw   equ Chipadr+$96  ;DMA control write register
  84. Aud0Lc    equ Chipadr+$a0  ;Channel 0 waveform sample location
  85. Aud0Len   equ Chipadr+$a4  ;Channel 0 waveform sample length
  86. Aud0per   equ Chipadr+$a6  ;channel 0 period
  87. Aud0vol   equ Chipadr+$a8  ;channel 0 volume
  88. Aud1Lc    equ Chipadr+$b0  ;Channel 1 waveform sample location
  89. Aud1Len   equ Chipadr+$b4  ;Channel 1 waveform sample length
  90. Aud1per   equ Chipadr+$b6  ;channel 1 period
  91. Aud1vol   equ Chipadr+$b8  ;channel 1 volume
  92. Setclr    equ $08000       ;DMA SEETCLR bit
  93. OffDMA    equ 0            ;Disable DMA
  94. Aud0en    equ $01          ;enable/disable Channel 0
  95. Aud1en    equ $02          ;Enable/disable Channel 1
  96. DMAen     equ $0200        ;Enable DMA
  97. timelsb   equ $bfe801      ;timer a Least sig byte - read last
  98. timemid   equ $bfe901      ;timer a middle byte
  99. timemsb   equ $bfea01      ;timer a MSB - read stops clock til LSB read 
  100. timecrb   equ $bfef01      ;timer a control register bit 7=0 is write
  101.  
  102. **  INCLUDE EQUATES FROM EITHER INCLUDE OR OUTFILE.EQU
  103. **  Do not use these [set not =] if using include or outfile.equ
  104.    IFEQ  1-useincludes  ;IF NOT ZERO THEN WILL NOT BE EQUATED
  105. wd_RPort   equ  $32
  106. wd_FirstGadget  equ  $3e
  107. wd_Size    equ  $7c
  108. ig_ImageData  equ  $0a
  109. ig_SIZEOF  EQU  $14
  110. wd_UserPort   equ   $56
  111. nw_FirstGadget equ  $12
  112. im_Class   equ   $14
  113. im_Code    equ   $18
  114. im_MouseX  equ   $20
  115. im_MouseY  equ   $22
  116. im_Seconds equ   $24
  117. im_Micros  equ   $28
  118. MP_FLAGS   EQU   $0E
  119. MP_SIGBIT  equ   $0f
  120. MP_SIGTASK EQU   $10
  121. MP_MSGLIST EQU   $14
  122. MP_SIZE    EQU   $22
  123. MENUENABLED   equ   $01
  124. MIDRAWN   equ   $100
  125. ITEMTEXT   equ   $02
  126. ITEMENABLED   equ   $10
  127. WBENCHSCREEN   equ   $01
  128. HIGHCOMP   equ   $40
  129. WINDOWSIZING   equ   $01
  130. WINDOWDRAG   equ   $02
  131. WINDOWDEPTH   equ   $04
  132. WINDOWCLOSE   equ   $08
  133. SMART_REFRESH   equ   $00
  134. ACTIVATE   equ   $1000
  135. GIMMEZEROZERO   equ   $400
  136. VANILLAKEY    EQU  $00200000    ;SEE OPENWINDOW IN INTUITION REF MANL
  137. FOLLOWMOUSE  EQU   $08
  138. CHECKIT  EQU $01        ;
  139. COMMSEQ  EQU $04
  140. MENUTOGGLE   EQU  $08
  141. TR_GETSYSTIME  EQU  $0A  ;used with the timer.device
  142. TR_SETSYSTIME  EQU  $0B
  143. TR_ADDREQUEST  EQU  $09
  144. CMD_READ  EQU  $02
  145. CMD_WRITE  EQU $03
  146. CMD_NONSTD EQU $09
  147. MN_REPLYPORT equ $0e
  148. MN_SIZE  EQU   $14
  149. IO_DEVICE  EQU   $14  ;THE IO_STDREQ STRUCTURE IS BEST DESCRIBED IN THE
  150. IO_UNIT    EQU   $18  ;ROM KERNAL SERIAL.DEVICE ON PG D40.
  151. IO_COMMAND  EQU  $1C
  152. IO_FLAGS   EQU   $1E
  153. IO_ERROR   EQU   $1F
  154. IO_ACTUAL  EQU   $20
  155. IO_LENGTH  EQU   $24
  156. IO_DATA    EQU   $28
  157. IO_OFFSET  EQU   $2C
  158. IOSTD_SIZE  EQU  $30
  159. IO_SIZE    EQU   $20
  160. IOTV_TIME  EQU   $20
  161. TV_SIZE    EQU   $08
  162. IOTV_SIZE  EQU   $28
  163. TV_SECS    EQU   $00
  164. TV_MICRO   EQU   $04
  165. UNIT_MICROHZ EQU $00
  166. UNIT_VBLANK  EQU $01
  167. pi_SIZEOF   EQU  $16
  168. pi_Flags    EQU  $00
  169. pi_HorizPot EQU  $02
  170. pi_VertPot  EQU  $04
  171. pi_HorizBody  EQU  $06
  172. pi_VertBody   EQU  $08
  173. pi_HPotRes  EQU  $0e
  174. pi_VPotRes  EQU  $10
  175. AUTOKNOB   EQU  $01
  176. FREEHORIZ  EQU  $02
  177. FREEVERT   EQU  $04
  178. KNOBHIT    EQU  $0100
  179. KNOBHMIN   EQU  6
  180. KNOBVMIN   EQU  4
  181. gg_NextGadget equ  $00
  182. gg_LeftEdge   equ  $04
  183. gg_TopEdge    equ  $06
  184. gg_Width      equ  $08
  185. gg_Height     equ  $0a
  186. gg_Flags      equ  $0c
  187. gg_Activation  equ  $0e
  188. gg_GadgetType  equ  $10
  189. gg_GadgetRender equ  $12
  190. gg_SelectRender  equ  $16
  191. gg_GadgetText  equ  $1a
  192. gg_MutualExclude  equ  $1e
  193. gg_SpecialInfo   equ  $22
  194. gg_GadgetID    equ  $26
  195. gg_UserData    equ  $28
  196. gg_SIZEOF    equ  $1c
  197. RELVERIFY  EQU  $01
  198. RIGHTBORDER  EQU  $10
  199. BOTTOMBORDER  EQU  $80
  200. PROPGADGET  EQU  $03
  201. GZZGADGET  EQU  $2000
  202. CLOSEWINDOW  EQU  $0200
  203. GADGETUP  EQU  $40
  204. MENUPICK  EQU  $0100
  205. GRELRIGHT  EQU  $10
  206. GRELHEIGHT  EQU  $40
  207. GRELWIDTH  EQU  $20
  208. GRELBOTTOM  EQU  $08
  209. GADGIMAGE  EQU  $04
  210. GADGHIMAGE  EQU  $02
  211. GADGHCOMP  EQU  $00
  212. RP_JAM1  EQU  $00
  213. RP_JAM2  EQU  $01
  214.  
  215.    ENDC
  216. ***  Program equates not defined in Include or Outfile.equ
  217. million   equ  1000000
  218. Priority  equ  $00
  219. maxspeed   equ  $a00
  220. linelen    equ 54      ;set to typed line length
  221. Count      equ $ffff   ;counter for delay timer
  222. bufferlen  equ 400  ;keyboard buffer length not more than #keybuf
  223. gwide   equ   22  ;how wide the gadget box is ( -GRELWIDTH)
  224. ghigh   equ  -40  ;how high the gadget box is (-GRELHEIGHT
  225. gleft   equ  -22  ;where the left edge of the box is (-GRELRIGHT)
  226. gtop    equ   15  ; -40  ;where the top of the box is (-GRELBOTTOM)
  227. g1wide  equ  300
  228. g1high  equ   12      ; -15
  229. g1left  equ   100
  230. g1top   equ  -12
  231. ** The following macro added by P.V.Inskeep, on 30,May,1987, to
  232. ** accomodate the need to copy a structure size into a program
  233. ** being written, and to consume the correct number of BYTES!
  234. ** It is also initialized to zero with the dcb.b command
  235.   IFND  MYSTRUCT    
  236. MYSTRUCT    MACRO     ;mystructname,mystructendaddr
  237. \1          dcb.b      \2,0
  238.         ENDM
  239.   ENDC
  240. start:
  241. ***   Open the Intuition Library ***
  242.    movea.l    #IntuitionName,a1     ;ask for intuition.library
  243.    clr.l      d0                    ;accept any version 0 or greater
  244.    movea.l    AbsExecBase,a6       ;the one fixed location in Amiga
  245.    jsr        _LVOOpenLibrary(a6)   ;assembly language programming
  246.    move.l     d0,IntuitionLibrary   ;store the pointer here
  247.    beq        Abort      ;if zero then open failed so we go away
  248. ** Open graphics - need for clear screen
  249.    movea.l    #GraphicsName,a1     ;ask for the graphics.library
  250.    clr.l      d0                   ;any version
  251.    movea.l    AbsExecBase,a6
  252.    jsr        _LVOOpenLibrary(a6)
  253.    move.l     d0,GraphicsLibrary   ;store the pointer here
  254.    beq        Abort
  255.  
  256. ***  Get some Chip Memory for Images, etc.
  257. getmem:      ;for image and audio
  258.     move.l   #imagebytes,d0   ;establish chip memory space for the 
  259.     move.l   #(MEMF_CHIP!MEMF_PUBLIC),d1   ;proportional gadgets and
  260.     movea.l  AbsExecBase,a6     ;the audio wave sample
  261.     jsr      _LVOAllocMem(a6)
  262.     tst.l    d0   ;a ptr to the memoryblock or 0 if error
  263.     beq      close2_image
  264.     move.l   d0,memblock   ;ptr to reserved memory block
  265.     move.l   d0,a0   ;ptr to reserved mem block
  266.     clr.l    d0    ;set up dbra register
  267.     move.l   #imagebytes,d0   ;#sizepubmem,d0   ;how many iterations
  268.     sub.l    #1,d0   ;goes to minus 1
  269.     lea.l    theimage,a1   ;ptr to beginning of initial data
  270. 1$  move.b   (a1)+,(a0)+   ;move data from begin to memblock
  271.     dbra     d0,1$  ;loop until all copied
  272. ;image2 - pitch - transformation
  273.     move.l   #pitchbytes,d0  
  274.     move.l   #(MEMF_CHIP!MEMF_PUBLIC),d1
  275.     movea.l  AbsExecBase,a6
  276.     jsr      _LVOAllocMem(a6)
  277.     tst.l    d0   ;a ptr to the memoryblock or 0 if error
  278.     beq      close3_pitch
  279.     move.l   d0,pitchblock   ;ptr to reserved memory block
  280.     move.l   d0,a0   ;ptr to reserved mem block
  281.     clr.l    d0    ;set up dbra register
  282.     move.l   #pitchbytes,d0   ;how many iterations
  283.     sub.l    #1,d0   ;goes to minus 1
  284.     lea.l    pitchimage,a1   ;ptr to beginning of initial data
  285. 3$  move.b   (a1)+,(a0)+   ;move data from begin to memblock
  286.     dbra     d0,3$  ;loop until all copied
  287. ;now the audio block moves to chip memory
  288.     move.l   #sizeaudio,d0
  289.     move.l   #(MEMF_CHIP!MEMF_PUBLIC),d1
  290.     movea.l  AbsExecBase,a6
  291.     jsr      _LVOAllocMem(a6)
  292.     tst.l    d0   ;a ptr to the memoryblock or 0 if error
  293.     beq      close4_audio
  294.     move.l   d0,audioblock   ;ptr to reserved memory block
  295.     move.l   d0,a0   ;ptr to reserved mem block
  296.     clr.l    d0    ;set up dbra register
  297.     move.l   #sizeaudio,d0   ;how many iterations
  298.     sub.l    #1,d0   ;goes to minus 1
  299.     lea.l    Wavesample,a1   ;ptr to beginning of initial data
  300. 2$  move.b   (a1)+,(a0)+   ;move data from begin to memblock
  301.     dbra     d0,2$  ;loop until all copied
  302. ***  Now initialize and open window and set pointers ***    
  303.    jsr    inits   ;set up some chip mem pointers
  304.    jsr    initializations  ;set lots of pointers and buckets
  305. ********** create timer port **********
  306. init_timerport:
  307. ;get a signal bit
  308.     moveq.l   #-1,d0
  309.     jsr       _LVOAllocSignal(a6)
  310.     move.l    d0,MP_Signalbit   ;d2
  311.     bmi       close5_sigbit   ; if -1 AllocSignal failed so abort
  312. ; alloc port structure
  313.     moveq.l   #MP_SIZE,d0  ;set aside this many bytes for message port
  314.     move.l    #(MEMF_CLEAR!MEMF_PUBLIC),d1 ;fill it with zeros
  315.     movea.l   AbsExecBase,a6
  316.     jsr       _LVOAllocMem(a6)  ;needs d0 and d1, if successful returns
  317.     move.l    d0,timerportptr  ;ptr to the memory set aside
  318.     beq       close6_MP        ;failed if zero
  319.  
  320. ; fill port fields
  321.     movea.l   timerportptr,a2      ;ptr to our MP_ structure
  322.     move.b    #NT_MSGPORT,LN_TYPE(a2)    ;Exec book pg A-30
  323.     move.b    #Priority,LN_PRI(a2) ;Priority = priority level 0
  324.     lea.l     TimerPortName,a1   ;name is "timer"
  325.     move.l    a1,LN_NAME(a2)     ; LN_NAME gets TimerPortName "timer"
  326.     move.l    MP_Signalbit,d2    ;bring back the signal bit. This puts the
  327.     move.w    d2,MP_FLAGS(a2)    ;signal bit in the lower 16 bits of d2,
  328. ; and writes them to the BYTES MP_FLAGS AND MP_SIGBIT
  329. ; Now find a task to put in the MP_SIGTASK field of the structure    
  330.     moveq.l   #0,d0  ;zero in a1 
  331.     movea.l   d0,a1  ;an odd way to zero out a1
  332.     jsr       _LVOFindTask(a6)  ;needs task or zero in a1
  333.     movea.l   timerportptr,a1     ;now switch ptr to a1
  334.     move.l    d0,MP_SIGTASK(a1)  ;task returned in d0, init sigtask
  335. ; add the port
  336.     movea.l   timerportptr,a1   ;there is no failure code for this,but
  337.     jsr       _LVOAddPort(a6)   ;it must be removed before the message
  338. ; initialize timerequest structure  ;port is closed 
  339.     moveq.l   #IOTV_SIZE,d0  ;Enough bytes for IO Timerequest Structure
  340.     move.l    #(MEMF_CLEAR!MEMF_PUBLIC),d1
  341.     jsr       _LVOAllocMem(a6)
  342.     tst.l     d0
  343.     beq   close7_remport  ;remove the port above and close out
  344.     move.l    d0,timeIOTVptr   ;save the IOTV ptr
  345.     move.l    d0,a0  ;now init our IOTV block.  This next step puts the
  346. ;message bit in high byte of word and priority bit in low byte, and
  347. ;stores them in a0+8 and a0+9 respectively
  348.     move.w    #((NT_MESSAGE<<8)+Priority),LN_TYPE(a0)
  349.     move.l    timerportptr,MN_REPLYPORT(a0) ; into a0+$0e
  350. ; the following flags should be cleared, and were in the AllocMem call
  351. ; but if not: clr.w  IO_FLAGS(timeIOTVptr)  ; this also zeros IO_ERROR
  352.     move.w    #TR_ADDREQUEST,IO_COMMAND(a0) ;this tells _LVODoIO what
  353. ;command we want it to do for us.
  354. OpenDeviceLOOP:
  355.     lea.l     timername,a0      ;name is "timer.device
  356.     movea.l   timeIOTVptr,a1    ;ptr to IOTV structure
  357.     moveq.l   #UNIT_MICROHZ,d0   ;use UNIT_MICROHZ or UNIT_VBLANK
  358.     moveq.l   #0,d1
  359.     movea.l   AbsExecBase,a6
  360.     jsr       _LVOOpenDevice(a6)  ;error if not successful
  361.     tst.l     d0
  362.     bne       close8_IOTV
  363.     bra       IntroMessage
  364.  
  365. delay3secs    movea.l   timeIOTVptr,a1   ;load our fully initialized IOTV ptr 
  366.     move.l    #3,IO_SIZE+TV_SECS(a1)  ;delay 3 seconds
  367.     move.l    #10,IO_SIZE+TV_MICRO(a1)  ;delay 10 microseconds
  368.     movea.l   AbsExecBase,a6  ;needs IO block in a1, returns error in
  369.     jsr       _LVODoIO(a6)    ;d0 or zero if successful
  370.     rts 
  371.  
  372. dotpause   movem.l  d0-d4/a0-a4,-(sp)    ;save the registers
  373.     jsr    conchar    ;get a key      
  374.     movea.l   timeIOTVptr,a1   ;load our fully initialized IOTV ptr 
  375.     move.l    secs,IO_SIZE+TV_SECS(a1)  ;for dot & space elements
  376.     move.l    micros,IO_SIZE+TV_MICRO(a1)  
  377.     movea.l   AbsExecBase,a6  ;needs IO block in a1, returns error in
  378.     jsr       _LVODoIO(a6)    ;d0 or zero if successful
  379.     movem.l  (sp)+,d0-d4/a0-a4
  380.     rts
  381. dashpause  movem.l  d0-d4/a0-a4,-(sp)    ;save the registers
  382.     jsr    conchar    ;get a key      
  383.     movea.l   timeIOTVptr,a1   ;load our fully initialized IOTV ptr 
  384.     move.l    dashsecs,IO_SIZE+TV_SECS(a1)  ;just for dashes
  385.     move.l    dashmicros,IO_SIZE+TV_MICRO(a1)
  386.     movea.l   AbsExecBase,a6  ;needs IO block in a1, returns error in
  387.     jsr       _LVODoIO(a6)    ;d0 or zero if successful
  388.     movem.l  (sp)+,d0-d4/a0-a4
  389.     rts
  390. initializations:   ; nothing works unless these are initialized before
  391. ; being used in the various routines.
  392.    move.l    #1,randflag  ;set random for keyboard input
  393.    move.l    #0,codecntr  ;zero out code counter
  394.    move.l    #0,kbcntr    ;zero out keyboard counter
  395.    move.l    #keybuf,kbptr     ;the current keyboard buffer position
  396.    move.l    #keybuf,codeptr   ;the current code char position
  397.    move.l    #keybuf,d0     
  398.    add.l     #bufferlen,d0      ;get to end of keybuf
  399.    move.l    d0,kbendptr  ;the end of keybuf
  400.    move.l    d0,consoleflag  ;make these two flags any non-zero
  401.    move.l    d0,timerflag    ;value so close1 works properly
  402.    move.l    #mymenu,menupoint   ;initialize pointer to menu structure
  403.    move.l    #menuitemone,firstmenuitem    ;init 1st menuitem pointer
  404.    move.l    #firstitemtext,itemonetext    ;init 1st item intuitext struct
  405.    move.l    #fititle,fitext               ;init title in 1st menu item
  406.    move.l    #menuitemtwo,menuitemone      ;init the second menu item
  407.    move.l    #seconditemtext,itemtwotext   ;and its text
  408.    move.l    #sititle,sitext
  409.    move.l    #menuitem3,menuitemtwo      ;init third menu item
  410.    move.l    #thirditemtext,item3text    ;and its text
  411.    move.l    #tititle,titext
  412.    move.l    #menuitem4,menuitem3
  413.    move.l    #forthitemtext,item4text
  414.    move.l    #fotitle,fotext
  415.    move.l    #onelinelist,oneline1    ;init drawline border coordinates
  416.    move.l    #onecharbuf,onecharptr   ;for writing one char
  417.    move.l    #5,ranword   ;for random char generator spacing
  418.    lea       buffer,a1    ;initialize the buffer
  419.    move.l    a1,bufptr    ;pointer
  420.    move.l    #0,secs      ;initialize the counters for dot and dash
  421.    move.l    #32000,micros   ;three to one ratio
  422.    move.l    #0,dashsecs
  423.    move.l    #112000,dashmicros
  424.    move.l    #2,factor    ;the speed factor menu adjuster
  425. ** Set the Menu Strip
  426.    movea.l   MyWindow,a0    ;pointers to window and to menu structure
  427.    movea.l   menupoint,a1   ;needed to call SetMenuStrip
  428.    movea.l   IntuitionLibrary,a6
  429.    jsr       _LVOSetMenuStrip(a6)
  430.    rts
  431. IntroMessage:
  432.    jsr   welcomssg  ;see if the messages work
  433.    move.l  #100,d0   ;this is a short pause routine to let
  434.                     ;the user read the intro message
  435.    jsr   pause      ;time to read the screen
  436.    jsr   setmessage     ;set up the message center
  437.    bra      openconsole
  438. *****  We went to the openconsole routine *****
  439.    cnop   0,4
  440. ** set up the IORequest block structure here
  441.    MYSTRUCT  myio,IOSTD_SIZE
  442.    cnop 0,4
  443. **  Open Console.Device
  444. **  Start by init the iodata field to a pointer to  MyWindow
  445. **  The open console device fills in all the rest.
  446. **  for the specific commands.  see Intuition manual pg 174
  447. openconsole:
  448. ;initialize to call adddevice
  449.    move.l   #myio,a0   ;the reserved block pointer is ioreqptr
  450.    move.l   a0,ioreqptr   ;set up a ioblock pointer
  451.    move.l   MyWindow,d1   ;get the window pointer
  452.    move.l   d1,IO_DATA(a0)  ;put the window ptr in IO_DATA
  453.    move.l   #wd_Size,IO_LENGTH(a0)   ;poke size of a window structure
  454. **open device
  455.    movea.l  #consolename,a0    ;console.device any other not do anything
  456.    move.l   #0,d0   ;unit number
  457.    movea.l  ioreqptr,a1   ;IORequest block structure i built
  458.    move.l   #0,d1  ;flags dont know what to put
  459.    movea.l  AbsExecBase,a6
  460.    jsr      _LVOOpenDevice(a6)  ;returns 0 if success, error if not
  461.    move.l   d0,consoleflag  ;keeps track of successful console open   
  462.    tst.l    d0    ;zero is success, not zero is error number
  463.    beq      success
  464.    bra      cl9_timerdevice ;close timer console et all
  465. success:
  466.    move.l  #iobuffer,d4  ;load a zero term mssg to print
  467.    jsr     conwrite   ;a short success message
  468.    tst.l   d0     ;zero is success
  469.    bne     close10  ;everything opened, but it didn't work
  470.    bra     passover  ;pass over the morse gadget initializations
  471.  
  472. ** put the message pointer in d4, with zero terminated
  473. conwrite:
  474.    movea.l  ioreqptr,a0   ;pointer to iorequestblock structure
  475.    move.l  #-1,IO_LENGTH(A0)  ;use -1 only if text null terminated.
  476. ;   otherwise, load iolength with buffer text length
  477.    move.l  d4,IO_DATA(A0)
  478.    move.w  #CMD_WRITE,IO_COMMAND(a0)    ;WORD LENGTH
  479.    movea.l a0,a1    ;iorequestblock structure
  480.    movea.l AbsExecBase,a6
  481.    jsr     _LVOSendIO(a6) ;DoIO works but waits for write to finish
  482.    rts                    ;and is therefore slower
  483. conread:
  484.    movea.l  ioreqptr,a0 
  485.    move.l  #10,IO_LENGTH(a0)   ;read a maximum of ten chars.
  486.    move.w  #CMD_READ,IO_COMMAND(a0)   ;set up the read command
  487.    move.l  a0,a1
  488.    move.l  bufptr,IO_DATA(a0)  ;fill the buffer from dos
  489.    movea.l AbsExecBase,a6
  490.    jsr     _LVOSendIO(a6)   ;88888errorcheck
  491.    rts
  492. **  Write one char in kbptr to the screen
  493. conwone:
  494.    movea.l  ioreqptr,a1   ;pointer to iorequestblock structure
  495.    move.l   #1,IO_LENGTH(a1)  ;use 1 to write one character
  496.    move.l   kbptr,IO_DATA(a1)
  497.    move.w   #CMD_WRITE,IO_COMMAND(a1)    ;WORD LENGTH
  498.    movea.l  AbsExecBase,a6
  499.    jsr      _LVOSendIO(a6)
  500.    rts
  501. ** Read one char fm keyboard (kbptr) 
  502. conrone:
  503.    movea.l  ioreqptr,a1  ;get ioreqblock base pointer
  504.    move.l   #1,IO_LENGTH(a1)   ;read 1 char
  505.    move.w   #CMD_READ,IO_COMMAND(a1)   ;set the read command
  506.    move.l   kbptr,IO_DATA(a1)  ;pointer where to store char
  507.    movea.l  AbsExecBase,a6     ;needs base ptr in a1
  508.    jsr      _LVOSendIO(a6)
  509.    rts
  510. ** gets a char if there is one in keyboard, and writes it.  This is called
  511. conchar:   ;during sounds of dots and dashes (dotpause-dashpause)
  512.    clr.l    d4   ;sending a dot or dash
  513.    movea.l  ioreqptr,a0
  514.    move.w   30(a0),d4  ;bit 6 of #30 in iorequest block will be 
  515.    btst     #14,d4   ;1 if a char is available in read, otherwise
  516.    beq      1$      ;it will be zero
  517.    jsr   conrone
  518.    jsr   conwone    ;there was a char
  519.    jsr   addkeyst   ;increment keyboard buffer ptr
  520. 1$  rts
  521.  
  522. *  Initialize the variables
  523. inits:
  524.    lea       image1,a0   ;gadget1 image structure ptr
  525.    movea.l   memblock,a1  ;ptr to gadget knob image data
  526.    move.l    a1,ig_ImageData(a0)  ;initialize image1 data ptr
  527.    lea       image2,a0
  528.    movea.l   pitchblock,a1
  529.    move.l    a1,ig_ImageData(a0)  ;init image2 data ptr
  530.    jsr   sound  ;initialize the sound subroutine
  531. ***   Open our window now that the propgadgets have been initialized
  532.    movea.l    #newwindow,a0
  533.    movea.l    IntuitionLibrary,a6
  534.    jsr        _LVOOpenWindow(a6)
  535.    move.l     d0,MyWindow        ;pointer to newly opened window
  536.    beq        Abort              ;the rastport pointer is located
  537.    movea.l    MyWindow,a0        ;at an address which is offset from
  538.    movea.l    wd_RPort(a0),a1    ;the window pointer by the value of
  539.    move.l     a1,myrport         ;wd_RPort, which is hex $32
  540.    rts
  541. passover:
  542.    jsr   setmessage   ;init these so DoIO can have a port
  543.    jsr   getmessage
  544.    jsr   sound    ;initialize the sound
  545.    clr.l  d0
  546.    move.w   #200,Aud0per   ;make a two tone sound to start up
  547.    move.w   #250,Aud1per   ;second channel should be lower pitch?
  548.    jsr    ChanneL0 ;make a noise
  549.    jsr    sound    ;reinit the sound
  550.    move.l #40,d0
  551.    jsr    pause 
  552.    jsr    sndon 
  553.    jsr    delay3secs ;just to see if it works
  554.    move.l #timertest,d4
  555.    jsr    conwrite
  556.    jsr    sndoff
  557.    move.l #40,d0
  558.    jsr    pause
  559.    jsr    clear
  560.    movea.l  #cqmssg,a5  ;addr of message to send
  561.    jsr    sendmorse
  562.    move.l  #endline,d4
  563.    jsr     conwrite
  564.    move.l   #testmsg,d4
  565.    jsr   conwrite  ;print instructions
  566.    tst.l  d0
  567.    bne    close1   ;if it fails
  568.    jsr    zerokeybuf   ;fill keybuf with zeros
  569.    jsr    conrone   ;read once to set to #14 bit  
  570.    bra   ponder3    ;to the main loop
  571. sendmorse:  ;expects pointer to 0 terminate string in a5
  572. 2$   clr.l   d0
  573.    move.b  (a5)+,d0     ;get 1st character from mssg
  574.    tst.b   d0    ;if 0 then done
  575.    beq     1$
  576.    move.l  a5,-(a7)   ;save mssg ptr
  577.    move.l  d0,-(a7)   ;save letter
  578.    move.b  d0,prtachar   ;load buffer
  579.    move.l  #prtachar,d4  ;prepare for conwrite
  580.    jsr     conwrite      ;write 0 terminated buffer
  581.    move.l  (a7)+,d0   ;get character back
  582.    jsr     sendone    ;send it as morse code sounds
  583.    move.l  (a7)+,a5   ;get mssg ptr back
  584.    bra     2$         
  585. 1$  rts
  586.  
  587. zerokeybuf:
  588.    move.l    #keybuf,a0  ;start of keyboard buffer
  589.    clr.l     d1
  590.    move.l    #bufferlen,d1    ;one less than buffer length
  591.    sub.l     #1,d1           
  592. 1$   move.b   #0,(a0)+   ;zero fill
  593.    dbra      d1,1$   ;decrement and branch
  594.    rts
  595.  
  596. ** The main routine for the menuitem selection.
  597. ** The Message Reading SubRoutine **
  598. ponder3:
  599.    jsr     getmessage  ;go see if there is a message to read
  600.    tst.l   d0    ;returns zero if none
  601.    beq     ponder5     ;return if no message
  602.    clr.l   d0  ;myclass contains the idcmp message upon [ponder4]
  603.    move.l  myclass,d0    ;return from getmessage
  604.    cmp.w   #MENUPICK,d0  ;was a menu picked
  605.    beq     whichmenu     ;if so, then go find out which menu item
  606.    cmp.w   #CLOSEWINDOW,d0   ;or was it the closewindow gadget?
  607.    beq     close1        ;if so, go close everything out
  608.    cmp.w   #GADGETUP,D0  ;or was the gadget hit to change speed
  609.    beq     chgspeed      ;change the delay loop values 
  610. ponder5:                 ;bra  keytest  ;no message
  611.    jsr    conchar     ;is there a char at keyboard
  612.    jsr    codetable   ;see if there is a char to send
  613.    bra    ponder3     ;loop back and do it again
  614.  
  615. ** Which Menu Item was selected?
  616. whichmenu:
  617.    clr.l   d0  ;mycode shows which menu item was selected
  618.    move.w   mycode,d0  ;mycode is word, not longword
  619. **  The next instructions masks mycode to isolate the six middle bits
  620. **  which contain the item number, and then compare it to item 1
  621.    and.w    #%0000011111100000,d0   ;15-11=sub; 10-5=item; 4-0=menu
  622.    cmp.w    #%0000000000000000,d0    ;0 is the 1st item #
  623.    beq      itemnr1    ;the 1st menu item was picked
  624.    cmp.w    #%0000000000100000,d0    ;1 is the 2nd item #
  625.    beq      itemnr2    ;the 2nd menu item was picked
  626.    cmp.w    #%0000000001000000,d0    ;10 is the 3rd item #
  627.    beq      itemnr3    ;the 3rd item was picked
  628.    cmp.w    #%0000000001100000,d0    ;11 is the 4th item#
  629.    beq      itemnr4    ;toggle the letter only switch
  630.    jsr      erase      ;erase rectangle bounded by above
  631.    move.l   #playmouse,IntuMsg    ;if not either of the above
  632.    move.w   #280,offsetleft       ;print the message play with
  633.    move.w   #5,offsettop         ;your mouse
  634.    jsr      printthis  ;prints string pointed to by IntuMsg
  635.    bra      ponder5    ;loop back to the beginning
  636. itemnr1:  ;send faster
  637.    jsr      erase
  638.    move.l   #pickitem1,IntuMsg  ;first item picked so
  639.    move.w   #270,offsetleft     ;print the message on the screen
  640.    move.w   #5,offsettop
  641.    jsr      printthis
  642.    jsr      meitem1    ;send faster
  643.    bra      chgspeed   ;thence to ponder5
  644. itemnr2:               ;send slower
  645.    jsr      erase
  646.    move.l   #pickitem2,IntuMsg  ;second item picked so
  647.    move.w   #270,offsetleft
  648.    move.w   #5,offsettop
  649.    jsr      printthis
  650.    jsr      meitem2   ;send slower
  651.    bra      chgspeed  ;thence to ponder5
  652. itemnr3:              ;switch random
  653.    jsr      erase
  654.    jsr      clear
  655.    move.l   #pickitem3,IntuMsg    ;third item picked
  656.    move.w   #270,offsetleft
  657.    move.w   #5,offsettop
  658.    jsr      printthis
  659.    jsr      meitem3   ;switch random on/off
  660.    bra      ponder5   ;use the same exit point
  661. itemnr4:
  662.    jsr      erase
  663.    move.l   #pickitem4,IntuMsg    ;Letter only Toggle Switch
  664.    move.w   #270,offsetleft
  665.    move.w   #5,offsettop
  666.    jsr      printthis
  667.    jsr      meitem4
  668.    bra      ponder5
  669. **  Random Number Generator  **
  670. random:
  671.     clr.l    d4
  672.     jsr      GETRANDOM  ;a random byte number in d0
  673.     and.l    #$7f,d0   ;want only letters
  674.     cmp.l    #43,d0    ;elim less than comma {,}
  675.     ble      random    ;go get another
  676.     cmp.l    #123,d0   ;letter z
  677.     bge      random
  678.     cmp.l    #97,d0    ;letter a or better
  679.     bge      1$
  680.     tst.l    letterflag   ;if not 0 then only letters
  681.     bne      random
  682.     cmp.l    #58,d0    ;number 9
  683.     bge      random
  684. 1$  cmp.l    lastrandom,d0
  685.     beq      random   ;if they are the same dont use it
  686.     jsr      aspace  ;see if time for a space
  687.     move.l   d0,-(sp)
  688.     lea      onecharbuf,a0
  689.     move.l   a0,d4
  690.     move.b   d0,(a0) 
  691.     jsr      conwrite  ;write it out
  692.     move.l   (sp)+,d0  ;get the character back
  693.     move.l   d0,lastrandom  ;store for comparison
  694.     rts   
  695.  
  696. GETRANDOM:
  697.    JSR   onerandom    ;make a random number
  698.    moveq    #0,d0      ;clear d0 long
  699.    MOVE.B   CELL1,D0   ;get the random # always in cell1
  700.    RTS      ;to from whence it came
  701. ** GENERATE RANDOM #'S FROM TRANSACTOR, MAY, 1987 
  702. ** MUST INITIALIZE WITH 21 RANDOM bytes
  703. onerandom:
  704.    moveq     #0,d0
  705.    moveq     #0,d1
  706.    moveq     #0,d2
  707.    move.b    CELL21,D0
  708.    add.b     CELL2,D0
  709.    move.b    d0,TMP
  710.    movea.l   #CBASE+21,a0
  711.    movea.l   #CBASE+22,a1
  712.    move.l    #19,D1
  713. 1$  move.b  -(A0),-(a1)        ;d2
  714.     dbra    d1,1$
  715.     move.b  TMP,CELL1  ;this is the random digit 
  716.     rts
  717. aspace:
  718.     move.l  ranword,d5  ;what's in ranword
  719.     tst.l   d5   ;if zero, then reseed
  720.     beq     1$
  721.     sub.l   #1,ranword  ;if not, reduce and return
  722. 2$  rts
  723. 1$  jsr     GETRANDOM  ;reseed the ranword
  724.     and.l   #$07,d0
  725.     or.l    #$01,d0
  726.     move.l  d0,ranword
  727.     move.l  #32,d0   ;put a space in the character generator
  728.     bra     2$
  729.     
  730. * CLEAR THE SCREEN**
  731. clear:
  732.    move.l   #clrscreen,d4  ;ascii 12,13,10,13,10,0
  733.    jsr      conwrite
  734.    rts   
  735.  
  736. setmessage:
  737.    movea.l  MyWindow,a0   ;pointer to my window
  738.    movea.l  wd_UserPort(a0),a0  ;pointer to our window's userport
  739.    move.l   a0,userport         ;save it
  740.    rts
  741. getmessage:
  742.    clr.l    d4               ;need this for junk
  743.    movea.l  userport,a0      ;get userport pointer for call to GetMsg
  744.    movea.l  AbsExecBase,a6  ;GetMsg is exec.lib, not intuition.lib
  745.    jsr      _LVOGetMsg(a6)
  746.    tst.l     d0               ;returns null if no message
  747.    beq      1$         ;escape if null
  748.    move.l   d0,idcmpmessage  ;pointer to this message structure needed
  749.    movea.l  idcmpmessage,a1  ;for address indirect with displacement
  750.    move.l   im_Class(a1),myclass  ;which ICDMP flag ie., MENUPICK
  751.    move.w   im_Code(a1),mycode    ;word-which menu item # 0,1,etc.
  752.    movea.l  AbsExecBase,a6  ;is pointed to by idcmpmessage, so that
  753.    jsr      _LVOReplyMsg(a6) ;messages don't pile up
  754.    move.l   idcmpmessage,d0  ;if d0 not 0 then return with message
  755. 1$    rts
  756.  
  757. ** Intuition Message
  758. welcomssg:
  759.    move.w   #10,offsettop
  760.    move.w   #50,offsetleft
  761.    move.l   #line1,IntuMsg    ;get pointer for first line to be
  762.    bsr      lineprint    ;printed
  763.    move.l   #line2,IntuMsg   ;second line
  764.    bsr   lineprint
  765.    move.l   #line3,IntuMsg
  766.    bsr   lineprint
  767.    move.l   #line4,IntuMsg
  768.    bsr   lineprint
  769.    move.l   #line5,IntuMsg
  770.    bsr   lineprint
  771.    move.l   #line6,IntuMsg
  772.    bsr   lineprint
  773.    move.l   #line7,IntuMsg
  774.    bsr   lineprint
  775.    rts
  776. lineprint   add.w    #20,offsettop
  777.    jsr      printthis
  778.    rts
  779.  
  780. ** the following will print what is in "IntuMsg"
  781. printthis:
  782.    movea.l   #0,a0   ;clear these else doesn't work
  783.    movea.l  #0,a1
  784.    clr.l    d0
  785.    clr.l    d1
  786.    movea.l  myrport,a0           ;pointer to rastport struct
  787.    movea.l  #intuitext,a1        ;pointer to intuitext struct
  788.    move.w   offsetleft,d0        ;leftedge offset
  789.    move.w   offsettop,d1         ;top edge offset
  790.    movea.l  IntuitionLibrary,a6  ;set library pointer
  791.    jsr      _LVOPrintIText(a6)   ;call print
  792.    rts
  793.  
  794. ** Pause routine expects delay value in d0, with constant 10000
  795. pause:
  796.    move.l   #10000,d1
  797.    move.l   d0,d2       ;put outter loop value in d2
  798. pause1   move.l  d1,d3  ;inner loop value in d3
  799. pause2      nop
  800.    dbra     d3,pause2   ;decrease inner loop till minus 1
  801.    dbra     d2,pause1   ;same for outter loop
  802.    rts                  ;all done
  803.  
  804. ** ERASE Part of Screen Routine - Fills a rectangle with the  **
  805. ** background color.  The rectangle is bounded by the starting
  806. ** and ending x,y coordinates (top left & bottom right)
  807. ** Start x pos in d0, end x pos in d1, both y pos' in d2
  808. ** Start at the bottom of the rectangleand draw lines in
  809. ** the background color up to the top of the screen
  810. erase:
  811.    move.w   #00,d0    ;now always erases the top 15 lines of screen
  812.    move.w   #612,d1
  813.    move.w   #15,d2
  814.    move.w   d0,stx         ;starting x position
  815.    move.w   d1,endx        ;ending x position
  816.    move.w   d2,sty         ;starting y position
  817.    move.w   d2,endy        ;ending y position
  818. grids1   jsr  drawline     ;draw one horizontal line a pixel high
  819.    subi.w   #1,sty         ;reduce y position
  820.    subi.w   #1,endy        ;reduce y position
  821.    dbra     d2,grids1      ;go back and draw another line
  822.    rts
  823.  
  824. **  call this subroutine to draw a single line from coordinates
  825. **  stx,sty to endx,endy - initialize those values before calling
  826. **  the subroutine by move.w   #nn,stx etc
  827. drawline:
  828.    movea.l  myrport,a0       ;pointer to our rastport
  829.    movea.l  #oneline,a1      ;pointer to border structure
  830.    move.l   #0,d0            ;offsets-left & top
  831.    move.l   #0,d1
  832.    move.l   IntuitionLibrary,a6
  833.    jsr      _LVODrawBorder(a6)
  834.    rts    
  835.  
  836. ***  Exit program -- Close all open whatevers  ***
  837. close1:
  838.    jsr   clear   ;clr the screen
  839.    lea.l   bestdx,a5
  840.    jsr   sendmorse
  841. close10:
  842.    movea.l  ioreqptr,a1
  843.    movea.l  AbsExecBase,a6
  844.    jsr      _LVOCloseDevice(a6)
  845. cl9_timerdevice    movea.l  timeIOTVptr,a1    ;ptr to IOTV structure
  846.    movea.l  AbsExecBase,a6
  847.    jsr      _LVOCloseDevice(a6)
  848. close8_IOTV
  849.    move.l   #IOTV_SIZE,d0   ;release timer IO Timerequest Structure
  850.    movea.l   timeIOTVptr,a1
  851.    movea.l   AbsExecBase,a6
  852.    jsr       _LVOFreeMem(a6)
  853. close7_remport   movea.l  timerportptr,a1  ;this closes both the port and
  854.    movea.l  AbsExecBase,a6  ;the MP_SIZE memory since the addport does not
  855.    jsr      _LVORemPort(a6) ;have a close of its own
  856.    move.l    #MP_SIZE,d0    ;release the timer message port
  857.    movea.l   timerportptr,a1
  858.    movea.l   AbsExecBase,a6
  859.    jsr       _LVOFreeMem(a6)
  860. close6_MP    move.l  MP_Signalbit,d0  ;free the signal bit
  861.    movea.l  AbsExecBase,a6
  862.    jsr      _LVOFreeSignal(a6)
  863. close5_sigbit   move.l    #sizeaudio,d0   ;this releases back to main memory the
  864.    movea.l   audioblock,a1   ;three blocks of memory that I allocated
  865.    movea.l   AbsExecBase,a6  ;for the speed prop gadget image, the 
  866.    jsr       _LVOFreeMem(a6) ;pitch prop gadget image and the audio
  867. close4_audio   move.l  #pitchbytes,d0  ;wave form
  868.    movea.l   pitchblock,a1
  869.    jsr       _LVOFreeMem(a6)
  870. close3_pitch   move.l  #imagebytes,d0
  871.    movea.l   memblock,a1
  872.    jsr       _LVOFreeMem(a6)
  873.    move.w   #200,offsetleft  ;position a goodbye message
  874.    move.w   #50,offsettop
  875.    move.l   #goodbye,IntuMsg
  876.    jsr      printthis
  877.    move.l   #50,d0 
  878.    jsr      pause           
  879. close2_image   movea.l   MyWindow,a0    ;clear the menu strip to
  880.    movea.l  IntuitionLibrary,a6      ;avoid conflicts when the
  881.    jsr      _LVOClearMenuStrip(a6)   ;program is ended
  882.    movea.l   MyWindow,a0
  883.    movea.l  IntuitionLibrary,a6
  884.    jsr      _LVOCloseWindow(a6)      ;now close the window
  885. Abort:
  886.    clr.l     d0
  887.    rts        ;all done, program has ended
  888.  
  889. **   The Code Table
  890. **   code element to be sent is in d0
  891. codetable:
  892.    jsr    getcodechar   ;get the next char fm keybuf
  893.    cmpi.b   #0,d0
  894.    beq      codet3  ;leave if char zero
  895.    jsr      seedrandom
  896. sendone   cmpi.b   #32,d0   ;is it a space? if so, skip code
  897.    beq      endword
  898.    movea.l  #alphacode,a0     ;get table pointer
  899.    clr.l    d1                ;clr counter
  900.    move.b   (a0),d1           ;set count at # of chars in table
  901.    adda.l   #1,a0             ;move up to beginning of table
  902. codet1   cmp.b  0(a0,d1),d0   ;index into table d1 bytes & compare
  903.    beq      codet2            ;char found
  904.    dbra     d1,codet1         ;decrement counter & try again
  905.    bra      codet3            ;exit-no match found
  906. codet2   move.b  d1,ltrcode   ;save the letter code number
  907.    jmp      findltr           ;get the letter
  908. codet4:
  909.    bne      codet3
  910.    move.l   d0,-(sp)        ;save char
  911.    move.l   #linelen,carreturn
  912.    move.l   (sp)+,d0        ;restore char
  913. codet3    rts   ;to keytest and start again
  914.  
  915. endword:
  916.    clr.l   d0
  917.    move.b  wordspce,d0       ;set up dbra loop
  918. endword1  jsr  dotpause      ;element    ;basic element spacing
  919.    dbra    d0,endword1
  920.    jmp     codet4            ;go update the line counter
  921.  
  922. findltr  move.b   ltrcode,d0  ;get the number back
  923.    add.b    d0,d0             ;double it
  924.    movea.l  #dotdash,a0       ;get table base
  925.    move.b   0(a0,d0),d1       ;the length of the code elements
  926.    subq.b   #1,d1             ;dec by one for dbra ending in -1
  927.    addq.b   #1,d0             ;up addr to code description
  928.    move.b   0(a0,d0),d2       ;get the morse letter
  929. nextelm  btst     d1,d2       ;if bit 1 then dash
  930.    bne.s    dash
  931. dot   jsr   sndon       ;turn on the sound
  932.    jsr    dotpause      ;element     ;sound one dot element
  933. elmstart jsr   sndoff   ;turn sound off
  934.    jsr    dotpause      ;noelement      ;char space
  935. elmdone  dbra     d1,nextelm  ;if not -1 then get next element
  936. endchar  clr.l    d1
  937.    move.b   charspce,d1       ;do the character space-3 elms
  938. endchar1 jsr   dotpause    ;element  ;make space rem to make charspce one
  939.    dbra     d1,endchar1       ;less than desired spaceing.
  940.    jmp      codet4            ;all done-get next character
  941. dash  jsr   sndon
  942.    jsr      dashpause   ;element ;this is longer by the weighting ratio
  943.    jmp      elmstart    ;the dash is done
  944.  
  945. ***  KeyBuffer Maintainence routine. Does not alter d0 ***
  946. addkeyst:
  947.    add.l   #1,kbptr
  948.    add.l   #1,kbcntr ;increment the keyboard counter
  949.    move.l  kbendptr,d4   ;set up a compare
  950.    cmp.l   kbptr,d4   ;is ptr less?
  951.    bgt     1$     ;d4 is > kbptr so branch
  952.    move.l  #keybuf,kbptr  ;reset to the beginnng
  953. 1$  rts
  954.  
  955. ** This gets a char and increments codeptr
  956. getcodechar:
  957.    clr.l   d1
  958.    clr.l   d0
  959.    move.l  randflag,d1
  960.    tst.l   d1           ;if zero, then fetch code from random routine
  961.    beq     random       ;this will send random code until menu changed
  962.    move.l  codecntr,d1  ;see that code does not get ahead of keyboard
  963.    cmp.l   kbcntr,d1    ;is d0 bigger, then dont send anything
  964.    bge     1$           ;just return until keyboard catches up
  965.    clr.l   d0
  966.    movea.l  codeptr,a0   ;set up indirect to get char to send
  967.    move.b  (a0),d0    ;get the char
  968.    add.l   #1,codeptr  ;increment before testing
  969.    add.l   #1,codecntr  ;increment the code counter
  970.    move.l  kbendptr,d4     ;are we at the end of the buffer
  971.    move.l  codeptr,d5
  972.    cmp.l   d5,d4 
  973.    bgt     1$     ;branch if d4 > codeptr
  974.    move.l  #keybuf,codeptr   ;reset to the beginning
  975. 1$   rts    ;returns with char in d0, & pointer incremented
  976.  
  977. ** Chage Speed With Proportional Gadget **
  978. chgspeed:
  979.     clr.l    d0  ;cuz we're going from word to long
  980.     clr.l    d1
  981.     moveq.l  #0,d2
  982.     lea.l    prop1,a0   ;get the prop struct base ptr
  983.     move.w   pi_VertPot(a0),d0   ;must be word length
  984.     move.l   factor,d1
  985.     mulu.w   d1,d0  ;this should max at 983040 microseconds
  986.     move.l   d0,micros
  987.     move.l   #0,secs   ;keep this at zero
  988.     move.l   d0,d1     ;triple this
  989.     add.l    d0,d1
  990.     add.l    d0,d1     ;now triple & perhaps over 1 meg
  991.     lsr.l    #1,d0        ;add 1/2 to make dash stretch a bit
  992.     add.l    d0,d1     ;now dash ratio is 3&1/2
  993. 1$   cmp.l  #million,d1  ;is d1 over one million
  994.     bls    2$      ;LS is low or same
  995.     sub.l   #million,d1
  996.     add.l   #1,d2  ;increase dashsecs
  997.     bra     1$     ;go back and try again
  998. 2$  move.l  d2,dashsecs
  999.     move.l  d1,dashmicros
  1000.     lea.l    prop2,a0   ;get pitch prop struct base ptr
  1001.     clr.l    d0
  1002.     move.w   pi_HorizPot(a0),d0   ;frequency  ;also word length
  1003.     divu     #40,d0     ;divide down by 40
  1004.     move.w   d0,frequency  ;store the new frequency
  1005.     jsr   sound
  1006. ;tell the screen that we did this
  1007.    jsr      erase
  1008.    clr.l    d0
  1009.    move.w   frequency,d0   ;check the pitch
  1010.    jsr      printhex       ;convert it to hex
  1011.    move.l   #hexprint,IntuMsg    ;print it
  1012.    move.w   #270,offsetleft   
  1013.    move.w   #5,offsettop      
  1014.    jsr      printthis
  1015.    clr.l    d0
  1016.    move.l   micros,d0    ;check the speed [dot unit]
  1017.    jsr      printhex       ;convert and print it
  1018.    move.l   #hexprint,IntuMsg
  1019.    move.w   #550,offsetleft
  1020.    move.w   #5,offsettop
  1021.    jsr      printthis
  1022.    move.l   #pitchmssg,IntuMsg
  1023.    move.w   #190,offsetleft
  1024.    jsr      printthis
  1025.    move.l   #speedmssg,IntuMsg
  1026.    move.w   #470,offsetleft
  1027.    jsr      printthis
  1028.    move.l   factor,d0    ;check the speed [dot unit]
  1029.    jsr      printhex       ;convert and print it
  1030.    move.l   #hexprint,IntuMsg
  1031.    move.w   #400,offsetleft
  1032.    move.w   #5,offsettop
  1033.    jsr      printthis
  1034.    bra      ponder5    
  1035.  
  1036. ** Independant Menu Picks **
  1037. ** send faster
  1038. meitem1:
  1039.    move.l   factor,d0
  1040.    subi.l   #1,d0     ;decrease factor if one or more
  1041.    move.l   d0,factor
  1042.    beq      meitem2   ;unless we get to zero
  1043.    rts
  1044. **  send slower
  1045. meitem2:
  1046.    addi.l   #1,factor
  1047.    move.l   factor,d0  ;factor should not be greater than 14
  1048.    cmp.l    #14,d0     ;or the program goes too slow.
  1049.    beq      meitem1
  1050.    rts
  1051. **  switch random = 0  keyboard = 1
  1052. meitem3:
  1053.    tst.l   randflag    ;what is current state?
  1054.    beq.s   1$    ;its zero, so we want to make it one
  1055.    move.l   #0,randflag  ;it was one, so make it zero
  1056. 2$  rts
  1057. 1$  move.l  #1,randflag  ;make it one
  1058.    move.l   codeptr,d4   ;reprint remaining keyboard buffer
  1059.    jsr      conwrite
  1060.    bra   2$    ;exit at one place
  1061. meitem4:
  1062.    tst.l  letterflag
  1063.    beq.s  1$   ;reverse switch
  1064.    move.l   #0,letterflag
  1065. 2$  rts
  1066. 1$  move.l  #1,letterflag
  1067.    bra   2$
  1068.  
  1069. sound:  ;Hardware Reference Manual describes this stuff
  1070.     movea.l audioblock,a2  ;Find address of waveform sample data
  1071.     move.l  a2,Aud0Lc      ;set waveform location channel 0
  1072.     move.l  a2,Aud1Lc      ;set waveform location channel 1
  1073. * Length = number of WORDS (not bytes) in waveform sample
  1074.     move.w  #16,Aud0Len    ;Set sample length channel 0
  1075.     move.w  #16,Aud1Len    ;set sample length channel 1
  1076. * volume can go up to 64
  1077.     move.w  #64,Aud0vol    ;Set channel 0 volume at maximum
  1078.     move.w  #64,Aud1vol    ;Set Channel 1 volume at maximum
  1079.     move.w  frequency,d0   ;bigger period higher sound
  1080.     move.w  d0,Aud0per     ;reset channel 0 period
  1081.     move.w  d0,Aud1per     ;set channel 1 period
  1082.     rts
  1083. ChanneL0:
  1084.     move.w  #(Setclr+DMAen+Aud0en),DMAconw     ;enable channel 0
  1085.     move.l  #30,d0
  1086.     bsr     pause 
  1087.     move.w  #(OffDMA+Aud0en),DMAconw           ;disable channel 0
  1088. ChanneL1:
  1089.     move.w  #(Setclr+DMAen+Aud1en),DMAconw     ;enable channel 1
  1090.     move.l  #45,d0
  1091.     jsr     pause 
  1092.     move.w  #(OffDMA+Aud1en),DMAconw           ;disable channel 1
  1093.     rts
  1094. sndon:
  1095.    move.w  #(Setclr+DMAen+Aud1en),DMAconw     ;turn sound on
  1096.    move.w  #(Setclr+DMAen+Aud0en),DMAconw     ;ch 0 & 1
  1097.    rts
  1098. sndoff:
  1099.    move.w  #(OffDMA+Aud1en),DMAconw   ;turn sound off
  1100.    move.w  #(OffDMA+Aud0en),DMAconw   ;ch 0 & 1
  1101.    rts
  1102.  
  1103. printhex:
  1104. ;prints a 16-bit hex number using d0 and hexfield
  1105.    clr.l   d1  ;nibble holder
  1106.    clr.l   d2  ;downcounter
  1107.    moveq   #3,d2
  1108.    lea.l   hexfield,a0
  1109.    lea.l   hexlist,a1
  1110.    bra     1$
  1111. 2$ sub.l   #1,d2
  1112.    asr.l   #4,d0  ;shift to next nibble 
  1113. 1$ move.l  d0,d1  ;move it 
  1114.    andi.l  #$0f,d1  ;what is the nibble
  1115.    move.b  0(a1,d1.l),d1  ;get the ascii equivalent
  1116.    move.b  d1,0(a0,d2.l)  ;put it in the hexfield
  1117.    tst.l   d2
  1118.    beq     3$
  1119.    bra     2$
  1120. 3$ rts
  1121.  
  1122. seedrandom:
  1123.    lea   CBASE,a0        ;this subroutine seeds the random # generator
  1124.    move.l basecounter,d1 ;when the user types in some letters to send
  1125.    move.b  d0,0(a0,d1.l) ;code.
  1126.    sub.l  #1,d1
  1127.    bmi    2$
  1128. 1$   rts
  1129. 2$   move.l  #19,basecounter
  1130.    bra    1$
  1131.  
  1132. yestheend:
  1133.       
  1134.    SECTION     data,DATA
  1135.  
  1136. CBASE    DC.B     19
  1137. CELL1    DC.B     24
  1138. CELL2    DC.B     37,42,55,68,73,86,91,100,112,128,134,146,159
  1139.          DC.B     165,171,180,197,205,212
  1140. CELL21   DC.B     223
  1141. TMP      DC.B     0,0,0,0
  1142.          CNOP     0,4
  1143.  
  1144. TimerPortName  dc.b  'timer',0
  1145. hexlist  dc.b  '0123456789abcdef',0
  1146. consolename  dc.b  'console.device',0
  1147. timername    dc.b  'timer.device',0
  1148. IntuitionName   dc.b  'intuition.library',0
  1149. GraphicsName    dc.b  'graphics.library',0
  1150. clrscreen       dc.b   12,13,10,13,10,0
  1151.     cnop   0,4    ;this is used to allign following stuff on a
  1152. **  long word address. If not done disaster can strike
  1153.  
  1154. menuflags   EQU   MENUENABLED!MIDRAWN   ;FROM INTUITION MENU STRUCTURE
  1155. itemflags   EQU   ITEMTEXT!ITEMENABLED!HIGHCOMP!COMMSEQ
  1156. item3flags  EQU   ITEMTEXT!ITEMENABLED!HIGHCOMP!CHECKIT!COMMSEQ!MENUTOGGLE
  1157. MyGadgets   EQU   WINDOWSIZING!WINDOWDRAG!WINDOWDEPTH!WINDOWCLOSE
  1158. MyFeatures  EQU   SMART_REFRESH!ACTIVATE!GIMMEZEROZERO   ;!VANILLAKEY
  1159. MyFlags     EQU   MyGadgets!MyFeatures
  1160. gadgrel     EQU   GRELRIGHT!GRELHEIGHT   ; !GRELBOTTOM
  1161. gadg1rel    EQU   GRELHEIGHT!GRELBOTTOM
  1162. gadgflags   EQU   GADGHIMAGE!GADGIMAGE
  1163. gadg1flags  EQU   GADGHIMAGE!GADGIMAGE
  1164. gadgtype    EQU   PROPGADGET!GZZGADGET
  1165. propflags   EQU   FREEVERT!KNOBHIT      ;!FREEHORIZ  !AUTOKNOB
  1166. prop1flags  EQU   KNOBHIT!FREEHORIZ           ;!AUTOKNOB
  1167. menupick    EQU   MENUPICK
  1168. MyTitle:    dc.b  '  Morse Code Practice by NO2D',0 ;title of our window
  1169. iobuffer    dc.b  ' All windows, structures & devices have opened.',10,10,13,0
  1170. menutitle   dc.b  ' Morse Menu',0      ;null term string
  1171. fititle     dc.b  '  Send Faster',0    ;first item in menu
  1172. sititle     dc.b  '  Send Slower',0   ;second item in menu
  1173. tititle     dc.b  '   Send Random',0   ;third menu item
  1174. fotitle     dc.b  '   Letters Only',0  ;forth menu item
  1175. offsetleft  dc.w  0
  1176. offsettop   dc.w  0
  1177. frequency   dc.w  420
  1178.       cnop   0,4
  1179.  
  1180. **  MENU and MENU ITEM STRUCTURES
  1181. mymenu:
  1182.    dc.l  0    ;menu pointer
  1183.    dc.w  0,0,200,100  ;leftedge,topedge,width,height
  1184.    dc.w  MIDRAWN!MENUENABLED  ;menuflags MENUENABLED & MIDRAWN
  1185.    dc.l  menutitle    ;pointer to title string
  1186. firstmenuitem  dc.l  0   ;pointer to first menu item (menuitemone)
  1187.    dc.w   0,0,0,0     ;for the jazz-beat (who knows what that means)
  1188.  
  1189. ** The first menu item structure **
  1190. menuitemone  dc.l  0     ;pointer to second menuitem
  1191.    dc.w  0,0,180,11      ;left,top,width,height of select box
  1192.    dc.w   itemflags      ;see flags set above
  1193.    dc.l   0              ;mutual exclude null=no item excluded
  1194. itemonetext   dc.l   0   ;pointer to intuitext struct for item text
  1195.    dc.l   0              ;pointer to highlight alternate image/text
  1196.    dc.b   70,0     ;set if COMMSEQ flag is set & a kluge byte 'f'
  1197.    dc.l   0       ;subitem if any
  1198.    dc.w   0       ;next selected item in drag 'mi_NextSelect'
  1199. ** remember to initialize all of these things
  1200. firstitemtext:
  1201.    dc.b  0,1,4,0  ;pens drawmode & kluge
  1202.    dc.w  0,0      ;leftedge,topedge
  1203.    dc.l  0        ;textfont null = default
  1204. fitext  dc.l  0   ;textpointer
  1205.    dc.l  0        ;pointer to next intuitext struct
  1206.  
  1207. ** The second menu item structure **
  1208. menuitemtwo  dc.l  0  ;pointer to third menuitem
  1209.    dc.w  0,15,180,11  ;left,top,width,height of select box
  1210.    dc.w   itemflags   ;see flags set above
  1211.    dc.l   0           ;mutual exclude null=no item excluded
  1212. itemtwotext   dc.l   0   ;aptr to intuitext struct for this item text
  1213.    dc.l   0              ;aptr to highlight alternate image/text
  1214.    dc.b   83,0     ;set if COMMSEQ flag is set & a kluge byte 's'
  1215.    dc.l   0       ;subitem if any
  1216.    dc.w   0       ;next selected item in drag 'mi_NextSelect'
  1217. ** remember to initialize all of these things
  1218. seconditemtext:
  1219.    dc.b  0,1,4,0  ;pens drawmode & kluge
  1220.    dc.w  0,0      ;leftedge,topedge
  1221.    dc.l  0        ;textfont null = default
  1222. sitext  dc.l  0   ;textpointer
  1223.    dc.l  0        ;pointer to next intuitext struct
  1224.    cnop  0,4
  1225.    
  1226. ** The forth menu item structure **
  1227. menuitem4  dc.l  0     ;pointer to second menuitem
  1228.    dc.w  0,45,180,11   ;left,top,width,height of select box
  1229.    dc.w   item3flags   ;see flags set above
  1230.    dc.l   0            ;mutual exclude null=no item excluded
  1231. item4text   dc.l   0   ;pointer to intuitext struct for item text
  1232.    dc.l   0            ;pointer to highlight alternate image/text
  1233.    dc.b   76,0     ;set only if COMMSEQ flag is set & a kluge byte
  1234.    dc.l   0       ;subitem if any
  1235.    dc.w   0       ;next selected item in drag 'mi_NextSelect'
  1236. ** remember to initialize all of these things
  1237. forthitemtext:
  1238.    dc.b  0,1,4,0  ;pens drawmode & kluge
  1239.    dc.w  0,0      ;leftedge,topedge
  1240.    dc.l  0        ;textfont null = default
  1241. fotext  dc.l  0   ;textpointer
  1242.    dc.l  0        ;pointer to next intuitext struct
  1243.    cnop   0,4
  1244.  
  1245. ** The third menu item structure **
  1246. menuitem3  dc.l  0     ;pointer to second menuitem
  1247.    dc.w  0,30,180,11   ;left,top,width,height of select box
  1248.    dc.w   item3flags   ;see flags set above
  1249.    dc.l   0            ;mutual exclude null=no item excluded
  1250. item3text   dc.l   0   ;pointer to intuitext struct for item text
  1251.    dc.l   0            ;pointer to highlight alternate image/text
  1252.    dc.b   65,0     ;set only if COMMSEQ flag is set & a kluge byte
  1253.    dc.l   0       ;subitem if any
  1254.    dc.w   0       ;next selected item in drag 'mi_NextSelect'
  1255. ** remember to initialize all of these things
  1256. thirditemtext:
  1257.    dc.b  0,1,4,0  ;pens drawmode & kluge
  1258.    dc.w  12,0      ;leftedge,topedge
  1259.    dc.l  0        ;textfont null = default
  1260. titext  dc.l  0   ;textpointer
  1261.    dc.l  0        ;pointer to next intuitext struct
  1262.  
  1263. **  An IntuiText Structure.  Use this to do the "printthis"
  1264. **  routine, with pointer to message in IntuMsg
  1265. intuitext:
  1266.   dc.b  1,1,2,0   ;FT & bk pen, drawmode, kluge
  1267.   dc.w  0,0       ;leftedge topedge
  1268.   dc.l  0         ;textfont normal if 0
  1269. IntuMsg  dc.l  0  ;pointer to null terminated text to be printed
  1270.   dc.l  0         ;next intuitext structure-null if none`
  1271.    cnop   0,4
  1272.  
  1273. line1  dc.b  'Welcome to the Morse Code Practice Program.',0
  1274. line2  dc.b  'It is designed to help you improve your Morse Code',0
  1275. line3  dc.b  'sending and receiving speed, with the hope that it',0
  1276. line4  dc.b  'will encourage you to get your amatuer radio license',0
  1277. line5  dc.b  'or to upgrade.  This is written in Assembly Language,',0
  1278. line6  dc.b  'and free distribution is encouraged.',0
  1279. line7  dc.b  'by Peter V. Inskeep, NO2D  -- CIS  72017,1211.',0
  1280. pitchmssg   dc.b  'Pitch =',0
  1281. speedmssg   dc.b  'Speed =',0
  1282. bestdx      dc.b  'best dx es 73 tu de no2d = \',0
  1283. goodbye     dc.b  'GOOD BYE NOW!  73 de  NO2D',0
  1284. pickgadget  dc.b  'Gadget Picked',0
  1285. pickitem1   dc.b  'Send Faster',0
  1286. pickitem2   dc.b  'Send Slower',0
  1287. pickitem3   dc.b  'Switch Code Source',0
  1288. pickitem4   dc.b  'Letter Only Toggle Switch',0
  1289. playmouse   dc.b  'Playing with your Mouse?',0
  1290.    cnop  0,2
  1291. cqmssg     dc.b   'cq cq cq de no2d no2d k',0
  1292.    cnop  0,4
  1293. longnull   dc.b   32,0,0,0,0
  1294.    cnop  0,4
  1295. hexprint   dc.b   '$ '
  1296. hexfield   dc.b   'fedc',0  ;five bytes, four used zero ends it
  1297.    cnop  0,4
  1298. ** A border structure to support the erase routine.
  1299. oneline:
  1300.   dc.w  0,0    ;left & top offsets
  1301.   dc.b  2,2    ;1,2 forground and background pens  ;33333
  1302.   dc.b  0      ;jam1 drawing modes
  1303.   dc.b  2      ;number of xy coordinates to be drawn
  1304. oneline1  dc.l  0    ;where the coordinates are (onelinelist)
  1305.   dc.l  0      ;next border structure-null if none
  1306.    cnop   0,4
  1307. onelinelist:
  1308. stx   dc.w  1    ;stuff these with the line starting and ending
  1309. sty   dc.w  1    ;coordinates for each line you want to draw
  1310. endx  dc.w  1    ;then call the border subroutine with the
  1311. endy  dc.w  1    ;oneline border structure address
  1312.    cnop    0,4
  1313. ************** Gadget Rendering Section  **************************;  
  1314. image2:
  1315.    dc.w   0,0,64,11,1
  1316.    dc.l   0   ;image data pointer
  1317.    dc.b   1,0
  1318.    dc.l   0
  1319.    cnop   0,4
  1320. image1:
  1321.    dc.w   0    ;left
  1322.    dc.w   0    ;top
  1323.    dc.w   16   ;no. of pixels wide 
  1324.    dc.w   14   ;no. of rows high
  1325.    dc.w   1    ;bitplane depth 1 or 2 for what I am doing use 1
  1326. im1addr   dc.l   0   ;testimage
  1327.    dc.b   1    ;PlanePick
  1328.    dc.b   0    ;PlaneOnOff
  1329.    dc.l   0    ;next image
  1330. prop2:
  1331.    dc.w   prop1flags 
  1332.    dc.w   $3000 ;pi_HorizPot  
  1333.    dc.w   $0   
  1334.    dc.w   $600   
  1335.    dc.w   $0   
  1336.    dc.w   20      
  1337.    dc.w   20      
  1338.    dc.w   500     
  1339.    dc.w   500     
  1340.    dc.w   0   ;g1left   
  1341.    dc.w   0   ;g1top    
  1342. prop1:
  1343.    dc.w   propflags    ;flags  00
  1344.    dc.w   0       ;pi_HorizPot  02
  1345.    dc.w   $4000   ;pi_VertPot   04  ;code speed for propgadget
  1346.    dc.w   $0      ;pi_HorizBody the portion of the total that will  06
  1347.    dc.w   $300    ;pi_VertBody show in the gadget window  08
  1348.    dc.w   20      ;pi_CWidth  0a
  1349.    dc.w   20      ;pi_CHeight  0c
  1350.    dc.w   500     ;pi_HPotRes  0e
  1351.    dc.w   500     ;pi_VPotRes  10
  1352.    dc.w   gleft   ;pi_LeftBorder  12
  1353.    dc.w   gtop    ;pi_TopBorder  14
  1354. gadget2:
  1355.    dc.l   0        ;ptr to next gadget in list
  1356.    dc.w   g1left    ;left edge of gadget relative or absolute
  1357.    dc.w   g1top     ;top edge of gadget relative or absolute
  1358.    dc.w   g1wide    ;width of the gadget itself
  1359.    dc.w   g1high    ;height of the gadget
  1360.    dc.w   gadg1flags!gadg1rel   ;flags
  1361.    dc.w   RELVERIFY!BOTTOMBORDER    ;!TOPBORDER ;activation
  1362.    dc.w   PROPGADGET!GZZGADGET   ;gadget type  (03) & ($2000)
  1363.    dc.l   image2   ;ptr- border, image, or none(0)
  1364.    dc.l   0   ;select render alternate border, image
  1365.    dc.l   0   ;g1itxt   ;gadget text if any
  1366.    dc.l   0   ;mutual exclude
  1367.    dc.l   prop2   ;special info for prop, string and interger gadgets
  1368.    dc.w   1   ;user defined gadget id field
  1369.    dc.l   0   ;pointer to user data
  1370.  
  1371. gadget1:
  1372.    dc.l   gadget2        ;ptr to next gadget in list
  1373.    dc.w   gleft    ;left edge of gadget relative or absolute
  1374.    dc.w   gtop     ;top edge of gadget relative or absolute
  1375.    dc.w   gwide    ;width of the gadget itself
  1376.    dc.w   ghigh    ;height of the gadget
  1377.    dc.w   gadgflags!gadgrel   ;flags
  1378.    dc.w   RELVERIFY!RIGHTBORDER    ;!TOPBORDER ;activation
  1379.    dc.w   PROPGADGET!GZZGADGET   ;gadget type  (03) & ($2000)
  1380.    dc.l   image1   ;ptr- border, image, or none(0)
  1381.    dc.l   0   ;select render alternate border, image
  1382.    dc.l   0   ;g1itxt   ;gadget text if any
  1383.    dc.l   0   ;mutual exclude
  1384.    dc.l   prop1   ;special info for prop, string and interger gadgets
  1385.    dc.w   1   ;user defined gadget id field
  1386.    dc.l   0   ;pointer to user data
  1387.    
  1388. **  A NEW WINDOW STRUCTURE - GADGETUP ADDED 8/27/87  **
  1389. newwindow:
  1390.   dc.w  0,0,640,200   ;Left,Top,Width,Height
  1391.   dc.b  0,1           ;DetailPen, BlockPen
  1392.   dc.l  CLOSEWINDOW!MENUPICK!GADGETUP         ;!FOLLOWMOUSE;IDCMFlags
  1393.   dc.l  MyFlags       ;Flags-described above
  1394.   dc.l  gadget1       ;gadget pointer load yours here 
  1395.   dc.l  0             ;CheckMark    Default
  1396.   dc.l  MyTitle       ;Title-see above
  1397.   dc.l  0             ;Screen: 0=Default
  1398.   dc.l  0             ;BitMap   Default
  1399.   dc.w  50,150,640,200 ;Minwidth,height;Maxwidth,height
  1400.   dc.w  WBENCHSCREEN  ;Type- customscreen is more work
  1401.   cnop   0,4
  1402. onecharbuf  dc.b  0,0,0,0,0,0,0,0  ;buffer for onechar (onecharptr)
  1403.    cnop   0,4
  1404. timertest dc.b 'Timer.device open and 3 sec delay executed',13,13,10,0   
  1405. testmsg  dc.b  ' MORSE CODE TEST PROGRAM  Ver. 1.1',13,10
  1406.   dc.b  '   by Peter Inskeep - NO2D',13,10
  1407.   dc.b  '   Original dated January 10, 1987',13,10,13,10
  1408.   dc.b  ' Type lower case characters on the keyboard.  Each',13,10
  1409.   dc.b  ' character should print on the screen and its morse',13,10
  1410.   dc.b  ' code will sound through both speakers.',13,10,10
  1411.   dc.b  ' Use the Prop Gadgets at the right edge and the bottom of',13,10
  1412.   dc.b  ' the window to change sending speed and pitch.',13,10,10
  1413.   dc.b  ' Or, use the Menu to send faster or slower,',13,10
  1414.   dc.b  ' or to switch between keyboard and random sending.',13,10
  1415.   dc.b  ' Choose to send random letters, or also numbers and',13,10
  1416.   dc.b  ' punctuation.',13,10,10
  1417.   dc.b  ' Learn morse code and become a Ham Radio Operator.',13,10,0
  1418.  
  1419. endline   dc.b  13,10,10,0
  1420. testbuff dc.b  '0',13,10,0
  1421.  
  1422. ** Timing counters for dot and dash sound elements
  1423. basecounter dc.l  19
  1424. charspce    dc.b  2
  1425. wordspce    dc.b  7
  1426. prtachar    dc.b  0,0,0,0
  1427.      cnop   0,4
  1428. alphacode:
  1429.   dc.b  43            ;44 chars in table [0-43]
  1430.   dc.b  '?.,-/=\;'    ;8 char ;=(._._.) \(..._._) ;(_..._)
  1431.   dc.b  '0987654321'  ;10 char
  1432.   dc.b  'jqyzxcpbvflowgdkurhsmnaite',0  ;26 char
  1433. dotdash:
  1434.   dc.b  6,%00001100   ; ?
  1435.   dc.b  6,%00010101   ; .
  1436.   dc.b  6,%00110011   ; ,
  1437.   dc.b  5,%00010001   ; -
  1438.   dc.b  5,%00010010   ; /
  1439.   dc.b  5,%00001010   ; =  .-.-.
  1440.   dc.b  6,%00000101   ; \  ...-.-
  1441.   dc.b  5,%00010001   ; ;  -...-
  1442.   dc.b  5,%00011111   ; 0
  1443.   dc.b  5,%00011110   ; 9
  1444.   dc.b  5,%00011100   ; 8
  1445.   dc.b  5,%00011000   ; 7
  1446.   dc.b  5,%00010000   ; 6
  1447.   dc.b  5,%00000000   ; 5
  1448.   dc.b  5,%00000001   ; 4
  1449.   dc.b  5,%00000011   ; 3
  1450.   dc.b  5,%00000111   ; 2
  1451.   dc.b  5,%00001111   ; 1
  1452.   dc.b  4,%00000111   ; j
  1453.   dc.b  4,%00001101   ; q
  1454.   dc.b  4,%00001011   ; y
  1455.   dc.b  4,%00001100   ; z
  1456.   dc.b  4,%00001001   ; x
  1457.   dc.b  4,%00001010   ; c
  1458.   dc.b  4,%00000110   ; p
  1459.   dc.b  4,%00001000   ; b
  1460.   dc.b  4,%00000001   ; v
  1461.   dc.b  4,%00000010   ; f
  1462.   dc.b  4,%00000100   ; l
  1463.   dc.b  3,%00000111   ; o
  1464.   dc.b  3,%00000011   ; w
  1465.   dc.b  3,%00000110   ; g
  1466.   dc.b  3,%00000100   ; d
  1467.   dc.b  3,%00000101   ; k
  1468.   dc.b  3,%00000001   ; u
  1469.   dc.b  3,%00000010   ; r
  1470.   dc.b  4,%00000000   ; h
  1471.   dc.b  3,%00000000   ; s
  1472.   dc.b  2,%00000011   ; m
  1473.   dc.b  2,%00000010   ; n
  1474.   dc.b  2,%00000001   ; a
  1475.   dc.b  2,%00000000   ; i
  1476.   dc.b  1,%00000001   ; t
  1477.   dc.b  1,%00000000   ; e
  1478.    cnop   0,4  
  1479.   SECTION   IMAGEDATA,DATA
  1480. beginpubmem:  
  1481. theimage:
  1482.    dc.w   %1111111111111111
  1483.    dc.w   %1100000000000011
  1484.    dc.w   %1100000000000011
  1485.    dc.w   %1100011111100011
  1486.    dc.w   %1100110000110011
  1487.    dc.w   %1100110000000011
  1488.    dc.w   %1100001111000011
  1489.    dc.w   %1100000000110011
  1490.    dc.w   %1100000000110011
  1491.    dc.w   %1100110000110011
  1492.    dc.w   %1100011111100011
  1493.    dc.w   %1100000000000011
  1494.    dc.w   %1100000000000011
  1495.    dc.w   %1111111111111111
  1496. imagebytes  equ *-beginpubmem
  1497. pitchimage:
  1498.  dc.w  %1111111111111111,%1111111111111111,%1111111111111111,%1111111111111111
  1499.  dc.w  %1100000000000000,%0000000000000000,%0000000000000000,%0000000000000011
  1500.  dc.w  %1100111110000111,%1111100001111111,%1110000001111000,%0001100000110011
  1501.  dc.w  %1100110001100000,%1100000001000110,%0010000011000110,%0001100000110011
  1502.  dc.w  %1100110001100000,%1100000000000110,%0000000110000000,%0001100000110011
  1503.  dc.w  %1100111110000000,%1100000000000110,%0000000110000000,%0001111111110011
  1504.  dc.w  %1100110000000000,%1100000000000110,%0000000110000000,%0001100000110011
  1505.  dc.w  %1100110000000000,%1100000000000110,%0000000011000110,%0001100000110011
  1506.  dc.w  %1100110000000111,%1111100000000110,%0000000001111000,%0001100000110011
  1507.  dc.w  %1100000000000000,%0000000000000000,%0000000000000000,%0000000000000011
  1508.  dc.w  %1111111111111111,%1111111111111111,%1111111111111111,%1111111111111111
  1509. pitchbytes  equ *-pitchimage
  1510.    dcb.w   50,1
  1511. sizepubmem equ *-beginpubmem
  1512.    cnop 0,4
  1513. beginaudio:  
  1514. Wavesample:
  1515.         dc.b 0,32,64,96,120,120,120,120,120,120,120,120
  1516.         dc.b 90,64,32,0,-32,-64,-90,-120,-120,-120
  1517.         dc.b -120,-120,-120,-120,-120,-120,-96,-64,-32,0
  1518. sizeaudio  equ *-beginaudio
  1519.   SECTION   mem,BSS
  1520. IntuitionLibrary   ds.l  1   ;keep address of Intuition here
  1521. GraphicsLibrary    ds.l  1   ;keep address of Graphics here
  1522. readbufptr    ds.l  1   ;for conread a 0 term string 
  1523. readbuffer    ds.l  100 ;storage for readbufptr
  1524. onecharptr    ds.l  1   ;pointer for one character write buffer
  1525. bufptr        ds.l  1   ;a general buffer pointer
  1526. buffer        ds.l  20  ;a one screen line buffer
  1527. ;handle        ds.l  1   ;console file read handle
  1528. prtbuff       ds.l  25  ;buffer for special print (end in 0)
  1529. prtptr        ds.l  1   :pointer for the spec.print buffer
  1530. codecntr      ds.l  1   ;counter for code sending
  1531. kbcntr        ds.l  1   ;counter for keyboard usage (with codecntr)
  1532. ltrcode       ds.l  1   ;store letter number here
  1533. carreturn     ds.l  1   ;holds carriage return in linelen
  1534. MyWindow      ds.l  1   ;address of the structure describing our window
  1535. mywdsize      ds.l  1   ;size of the window 
  1536. bucket        ds.l  1   ;a place to dump things
  1537. userport      ds.l  1   ;pointer to wd_UserPort structure
  1538. myclass       ds.l  1   ;ICDMP Class or equal to flag ie., MENUPICK
  1539. menupoint     ds.l  1   ;pointer to menu structure
  1540. idcmpmessage  ds.l  1   ;the message class reported by intuimessage
  1541. myrport     ds.l   1   ;this windows rastport
  1542. secs        ds.l   1   ;seconds in IntuiMessage
  1543. micros      ds.l   1   ;microseconds in IntuiMessage
  1544. dashsecs    ds.l   1   ;for the dash seconds
  1545. dashmicros  ds.l   1   ;for the dash micros
  1546. keybuf      ds.l  bufferlen    ;keystroke buffer 
  1547. kbptr       ds.l   1   ;keybuf current position pointer
  1548. kbendptr    ds.l   1   ;end of keybuf pointer
  1549. codeptr     ds.l   1   ;code sending current position (not same as kbptr)
  1550. randflag    ds.l   1   ;random flag 1=keyboard 0=random
  1551. consoleflag  ds.l  1   ;flag for success opening console 0=success
  1552. timerflag   ds.l   1   ;same for timer
  1553. letterflag  ds.l   1   ;letter only flag switch
  1554. timerbase   ds.l   1   ;see pg b3, Rom Kernal Manual
  1555. ioreadbuffer   ds.l   20 ;read buffer 80 characters max
  1556. iowritbuf   ds.l   1   ;one char write buffer, but longword
  1557. ioreadbuf   ds.l   1   ;one char read buffer, but longword
  1558. ioreqptr    ds.l   1   ;pointer to io request block
  1559. ranword     ds.l   1   ;a cntr for random word space
  1560. memblock    ds.l   1   ;pointer to image data in memory
  1561. pitchblock  ds.l   1   ;ptr to pitch image data
  1562. audioblock  ds.l   1   ;ptr to audio data block
  1563. lastrandom  ds.l   1   ;store the last random # here
  1564. counter     ds.l   1   ;a general counter 
  1565. timerportptr  ds.l   1   ;pointer to chip reply messageport structure
  1566. timeIOTVptr   ds.l   1  ;a pointer to timerequest structure IOTV_
  1567. MP_Signalbit  ds.l   1  ;signal bit for the timerportptr
  1568. factor        ds.l   1  ;times factor for speed
  1569. mousex      ds.w   1   ;x mouse coordinate
  1570. mousey      ds.w   1   ;y mouse coordinate
  1571. mycode      ds.w   1   ;for things line menu# ie, 0,1,2,3, etc.
  1572. infrequency ds.w   1   ;holds sound frequency fm horizpot
  1573.  
  1574.    END    
  1575.